package logic

import (
	"context"
	"shuqi-novel/models/mysql"

	"shuqi-novel/userrpc/internal/svc"
	"shuqi-novel/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookAddLogic {
	return &BookAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 小说添加
func (l *BookAddLogic) BookAdd(in *userrpc.BookAddRequest) (*userrpc.BookAddResponse, error) {
	// todo: add your logic here and delete this line

	book := &mysql.Books{
		UserId: in.UserId,
		Title:  in.Title,
	}
	err := book.BookAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &userrpc.BookAddResponse{
		BookId: int64(book.ID),
	}, nil
}
